/*
 * author	: jack
 * email	: xulongzhong2004@163.com
 *
 * Licensed under the LGPL v2.1, see the file LICENSE in base directory.
 */

#include "tproxy_in.h"

/*
static int Recvn( int fd, void *buf, int len, long *p_timeout )
{
	int 		nret;
	int 		n = len ;
	char 		*rev_buf = (char*)buf;
	struct pollfd 	poll_fd;
	struct timeval	tvBegin , tvEnd ;
	long 		timeout_usec = 0;
	long		poll_timeout = -1;
	
	if ( fd < 0 || !buf || len <= 0 )
		return -1;
		
	if( p_timeout )
	{
		poll_timeout = *p_timeout; 
		timeout_usec = *p_timeout*1000;
	}
		
	poll_fd.fd = fd;
	poll_fd.events = POLLIN;
	
	while( n > 0 )
	{
		gettimeofday( & tvBegin , NULL );
		nret = poll( &poll_fd , 1 , poll_timeout );
		if( nret < 0 )
			return NSPROXY_POLL_ERROR;

		gettimeofday( & tvEnd , NULL );
		
		if( p_timeout )
		{
			timeout_usec -= ( tvEnd.tv_sec *1000*1000 + tvEnd.tv_usec ) - ( tvBegin.tv_sec *1000*1000 + tvBegin.tv_usec );
			poll_timeout = timeout_usec/1000;
			if( poll_timeout <= 0 )
				break;
		}
		if( nret > 0 )
		{
			nret = recv( fd , rev_buf , n , 0 );
			if( nret <= 0 )
				return NSPROXY_SOCKET_CLOSED;
			
			n -= nret;
			rev_buf += nret;
		}
	}
	
	if( n > 0 )
		return NSPROXY_POLL_TIMEOUT;
	
	if( p_timeout )
		*p_timeout = poll_timeout;
	
	return 0;
}
*/
